// ProjectName: go-learn-demo
// PackageName: xormybxb
// Description:
// Author: hy.bai
// Date: 2025-08-20 星期三 16:56

package xormybxb

import (
	"fmt"
	"log/slog"
)

func TestQueryDemo() {
	InitEngine()
	// 注:result是[]map[string][]byte类型。即：是一个Map类型的切片
	result, _ := MysqlEngine.Query("select * from t_user")
	for ind := range result {
		objMap := result[ind]
		for key, val := range objMap {
			fmt.Println(key, ":", string(val))
		}
		fmt.Println("---------------------------------")
	}
}

func TestQueryInterfaceDemo() {
	InitEngine()
	// 注:result是[]map[string]interface{}类型。即：是一个Map类型的切片
	result, _ := MysqlEngine.QueryInterface("select * from t_user")
	for ind := range result {
		objMap := result[ind]
		for key, val := range objMap {
			fmt.Println(key, ":", val)
			fmt.Printf("%T:%v\n", val, val)
		}
		fmt.Println("---------------------------------")
	}
}

func TestSqlUpdate() {
	InitEngine()
	sql := "update `t_user` set username=? where id=?"
	result, err := MysqlEngine.Exec(sql, "xiaolun", 3)
	if err != nil {
		slog.Error("数据更新失败,原因是:", err.Error())
	}
	rowsAffected, _ := result.RowsAffected()
	fmt.Println("操作结果:", rowsAffected)
}
